function double_cluster_dt_for_GUI(dt,h)

%double_cluster_dt_for_GUI double clustering for Create New Model GUI

if nargin<2 % a specific GUI can be targetted by setting h 
    h=gcf; % otherwise use current figure
end

%get(gca);
D=dt.nx;
%cm=get(findobj('Tag','color_map'),'UserData');
%if ~isempty(cm);colormap(cm);end
    
% Horizontal dendrogram (variables)
hx=findobj(h,'Tag','x_cluster');
axes(hx);
set(hx,'Visible','on');
n=length(dt.nx(1,:));
[a,b,Ix]=dendrogram(linkage(pdist(dt.nx')),n);
ylabel('Linkage distance','FontSize',min([4+100/n,8]))
ax=axis;text(ax(1)+(ax(2)-ax(1))/2,ax(4)+(ax(4)-ax(3))/10,'Variables')
set(hx,'XTickLabel','','FontSize',min([4+100/n,8]));%remove labels, change font size
%n=length(dt.x(1,:));
for i=1:n %rotate new text labels
    text(i,ax(3)-0.05*(ax(4)-ax(3)),dt.vars(Ix(i)),'HorizontalAlignment','left','rotation',-90,'FontSize',min([4+100/n,8]));
end
set(hx,'Tag','x_cluster');

% Vertical dendrogram (samples)
hy=findobj(h,'Tag','y_cluster');
axes(hy);
set(hy,'Visible','on');
m=length(dt.nx(:,1));
[a,b,Iy]=dendrogram(linkage(pdist(dt.nx)),m,'Orientation','left');
set(hy,'XAxisLocation','top');xlabel('Linkage distance')
for i=1:length(dt.samples);dt.samples{i}=[' ',dt.samples{i}];end
set(hy,'YTickLabel',dt.samples(Iy),'FontSize',min([4+100/m,8]));
ax=axis;text(ax(2)+(ax(2)-ax(1))/10,ax(3)+(ax(4)-ax(3))/2,'Samples','Rotation',90)
hold on
cm=colormap;
if isempty(cm);
    colormap default
    cm=colormap;
end
cn=length(cm(:,1));ymin=min(dt.y);dy=max(dt.y)-ymin;c=floor((cn-1)*(dt.y-ymin)/dy)+1;
for i=1:m
    %if dt.y(Iy(i))==1
    %  plot(ax(1),i,'o','MarkerSize',4,'MarkerFaceColor','k','MarkerEdgeColor','k')
    %else
    %    plot(ax(1),i,'o','MarkerSize',4,'MarkerFaceColor','w','MarkerEdgeColor','k')
    %end
    if dt.dead(Iy(i))
        plot(ax(1),i,'s','MarkerSize',5,'MarkerFaceColor',cm(c(Iy(i)),:),'MarkerEdgeColor','k')
    else
        plot(ax(1),i,'o','MarkerSize',4,'MarkerFaceColor',cm(c(Iy(i)),:),'MarkerEdgeColor','k')
    end
end
hold off
set(hy,'Tag','y_cluster');

% Data image matrix

hxy=findobj(h,'Tag','double_cluster');
axes(hxy);
himg=imagesc(dt.nx(Iy(end:-1:1),Ix));G=get(himg);
set(G.Parent,'XTick',[],'YTick',[]);
%axis off
Px=get(hx,'Position');
Py=get(hy,'Position');
P=[Px(1),Py(2),Px(3),Py(4)];
set(hxy,'Position',[P(1)+P(3)/(2*n),P(2)+P(4)/(2*m),P(3)-P(3)/n,P(4)-P(4)/m]);
set(hxy,'Tag','double_cluster');

% Colorscheme
hcolor=findobj(h,'Tag','color_scale');
axes(hcolor);
set(hcolor,'Visible','on');
%y=[min(dt.y):(max(dt.y)-min(dt.y))/100:max(dt.y)];
%y=unique(dt.y);
mycolorbar(unique(dt.y));
set(hcolor,'Tag','color_scale');
%disp(':-)')


